from langgraph.graph import StateGraph,START,END
from typing_extensions import TypedDict,Annotated

bulider = StateGraph(dict)
def add_node(state):
  return {'x':state['x']+1}
def condtion_node1(state):
  print('现在是第一条路哦')
  return {'y':state['x']}
def condtion_node2(state):
  print('现在是第二条路哦')
  return{'z':state['x']}
def routing_function(state):
    return state['x']%2==0
 
bulider.add_node('加一',add_node)
bulider.add_node('第一条路',condtion_node1)
bulider.add_node('第二条路',condtion_node2)
bulider.add_edge(START,'加一')
bulider.add_conditional_edges('加一',routing_function,{True:'第一条路',False:'第二条路'})
bulider.add_edge('第一条路',END)
bulider.add_edge('第二条路',END)
graph = bulider.compile()
print(graph.invoke({'x':1}))



